package com.xh.bussiness.longwen.controller;

import com.xh.bussiness.longwen.bean.request.QueryStudentRequest;
import com.xh.bussiness.longwen.bean.request.QueryTeacherPaikeRequest;
import com.xh.bussiness.longwen.service.IApiService;
import com.xh.bussiness.thirdapi.LongwenApi;
import com.xh.core.bean.AjaxResult;
import com.xh.core.bean.XhPage;
import com.xh.core.constant.AjaxResultConstant;
import com.xh.core.util.DateUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Calendar;

/**
 * <p>
 *
 * </p>
 *
 * @author Pitt zhang
 * @since 2019/8/30
 */
@Api(tags = "龙文对外接口")
@RestController
@RequestMapping("/longwen/api")
public class ApiController {

    @Autowired
    private IApiService apiService;

    @RequestMapping("/queryTeacherPaikeList")
    @ApiOperation("查询教师排课信息")
    public AjaxResult queryTeacherPaikeList(XhPage page, QueryTeacherPaikeRequest request) {
        page = apiService.queryTeacherPaikeList(page, request);
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS, page);
    }


    @RequestMapping("/queryStudentPaikeList")
    @ApiOperation("查询学生排课信息")
    public AjaxResult queryStudentPaikeList(XhPage page, QueryTeacherPaikeRequest request) {
        page = apiService.queryStudentPaikeList(page, request);
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS, page);
    }

    @ApiOperation("查询老师一对一学员")
    @GetMapping("/queryTeacherOneByOneStudents")
    public AjaxResult queryTeacherOneByOneStudents(XhPage page, QueryTeacherPaikeRequest request) {
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS, LongwenApi.queryTeacherOneByOneStudents(page.getCurrent(), page.getSize(), request));
    }

    @ApiOperation("查询老师小班数据")
    @GetMapping("/queryTeacherXiaoban")
    public AjaxResult queryTeacherXiaoban(XhPage page, QueryTeacherPaikeRequest request) {
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS, LongwenApi.queryTeacherXiaoban(page.getCurrent(), page.getSize(), request));
    }


    @GetMapping("/queryArea")
    @ApiOperation("查询地区")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "areaType", value = "区域级别 [[0,'全国'],[2,'市级'],[3,'校区'],[4,'教学点']]", required = true, dataType = "Integer"),
    })
    public AjaxResult queryArea(Integer areaType) {
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS, apiService.queryArea(areaType));
    }

    @GetMapping("/querySchoolByAreaId")
    @ApiOperation("根据区域id查询校区")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "areaId", value = "区域ID", required = true, dataType = "Integer"),
    })
    public AjaxResult querySchoolByAreaId(Integer areaId) {
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS, apiService.querySchoolByAreaId(areaId));
    }

    @GetMapping("/queryTeacherBySchoolId")
    @ApiOperation("根据校区查询教师数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "schoolId", value = "校区ID", required = true, dataType = "Integer"),
    })
    public AjaxResult queryTeacherBySchoolId(XhPage page,Integer schoolId) {
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS, LongwenApi.queryTeacherBySchoolId(page,schoolId));
    }


    @GetMapping("/queryStudentByParams")
    @ApiOperation("查询一对一学生/小班学生")
    public AjaxResult queryStudentByParams(QueryStudentRequest request) {
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS, apiService.queryStudentByParams(request));
    }

    @GetMapping("/queryStudentOneByOneContract")
    @ApiOperation("查询一对一学生合同")
    @ApiImplicitParam(value = "studentId", name = "学生id", required = true)
    public AjaxResult queryStudentOneByOneContract(Integer studentId) {
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS, LongwenApi.queryStudentOneByOneContract(studentId));
    }

    /**
     * 根据合同id查询学生信息
     *
     * @param contractId
     * @return
     */
    @ApiOperation("根据合同id查询学生信息")
    @GetMapping("/queryStudentInfoByContractId")
    @ApiImplicitParam(value = "contractId", name = "合同id", required = true)
    public AjaxResult queryStudentInfoByContractId(Integer contractId) {
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS, LongwenApi.queryStudentInfoByContractId(contractId));
    }

    /**
     * 小班查询学生信息
     *
     * @param classId
     * @return
     */
    @ApiOperation("小班查询学生信息")
    @ApiImplicitParam(value = "classId", name = "班级id", required = true)
    @GetMapping("/queryStudentByClassId")
    public AjaxResult queryStudentByClassId(Integer classId) {
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS, LongwenApi.queryStudentByClassId(classId));
    }

    /**
     * 查询教师排课日历
     *
     * @param request
     * @return
     */
    @ApiOperation("查询教师排课日历")
    @GetMapping("/queryTeacherPaikeCalendar")
    public AjaxResult queryTeacherPaikeCalendar(QueryTeacherPaikeRequest request) {
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.YEAR, request.getYear());
        cal.set(Calendar.MONTH, request.getMonth() - 1);

        request.setStartTime(DateUtils.format(DateUtils.getFirstDayOfMonth(cal.getTime()), "yyyy-MM-dd"));
        request.setEndTime(DateUtils.format(DateUtils.getLastDayOfMonth(cal.getTime()), "yyyy-MM-dd"));

        return new AjaxResult(AjaxResultConstant.Result.SUCCESS, LongwenApi.queryTeacherPaikeCalendar(request));
    }

    @ApiOperation("查询教师下的一对一和小班数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lwUserId", value = "龙文教师id", dataType = "String", required = true),
            @ApiImplicitParam(name = "lwSchoolId", value = "龙文校区id", dataType = "String", required = true),
            @ApiImplicitParam(name = "businessType", value = "查询业务类型（1：错题；2：备课；）")
    })
    @RequestMapping("/queryStudentAndClassByTeacherId")
    public AjaxResult queryStudentAndClassByTeacherId(String lwUserId, String lwSchoolId, Integer businessType) {
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS, apiService.queryStudentAndClassTeacherId(lwUserId, lwSchoolId, businessType));
    }

    @ApiOperation("查询龙文地区和校区数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lwUserId", value = "龙文教师id", dataType = "String", required = true),
    })
    @RequestMapping("/queryAreaByParentId")
    public AjaxResult queryAreaByParentId(Integer parentId) {
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS, LongwenApi.queryAreaByParentId(parentId));
    }

}
